$(function() {

	$('#verifyTable').bootstrapTable({
		data : getDatas(),
		striped : true,
		cache : false,
		pagination : true,
		sortable : false,
		toolbar : "#verifyToolBar",
		sidePagination : "client",
		pageNumber : 1,
		pageSize : 10,
		pageList : [ 10, 25, 50, 100 ],
		search : true,
		strictSearch : false,
		showColumns : true,
		clickToSelect : true,
		uniqueId : 'id',
		columns : [ 
		{
			field : 'customerName',
			title : '报修客户'
		}, {
			field : 'deviceName',
			title : '报修设备'
		}, {
			field : 'verifyResultShow',
			title : '审核结果'
		}, {
			field : 'verifyReasonHideOverflow',
			title : '审核理由'
		}, {
			field : 'verifyTime',
			title : '审核时间',
			formatter : function(value, row, index) {
				return moment(value).format('YYYY-MM-DD HH:mm:ss');
			}
		}],
		onDblClickRow : function(row) {// 双击查看详情
			showBillDetail(row);
		}
	});

	$("#verifyTable").bootstrapTable("hideColumn", "id");
});

 

function getDatas() {
	var verifys = '';
	$.ajax({
		url : "../verify/query.action",
		type : "post",
		async : false,// 是为了内层ajax在之后访问
		success : function(data) {
			$(data).each(function() {
				this.bill = getBillById(this.billId);
				this.verifyResultShow = getVerifyResult(this.verifyResult);
				this.verifyReasonHideOverflow = '<div class=\'td-cont-3\'>'+this.verifyReason + '</div>';
				this.deviceName = this.bill.deviceName;
				this.customerName = this.bill.customerName;
			});
			verifys = data;
		},
		error : function() {
			toastr.error("获取报修信息发生出错，请联系管理员");
		}
	});
	return verifys.reverse();
}

function getVerifyResult(result) {
	if (result == '1') {
		return '审核通过';
	} else {
		return '审核拒绝';
	}
}

//详情
function showBillDetail(verify) {
	
	var verifyDetailHtml = '<p styverifytext-align: center; color: #6294AD;"><b>基本信息</b></p>'
		+	'<p>id：' + verify.id + '</p>'
		+	'<p>报修客户：' + verify.customerName + '</p>'
		+	'<p>报修设备：' + verify.deviceName + '</p>'
		+	'<p>审核结果：' + verify.verifyResultShow + '</p>'
		+	'<p>审核时间：' + getFormatTime(verify.verifyTime,"YYYY-MM-DD") + '</p>'
		+	'<p>审核理由：<pre style="white-space: pre-wrap !important;word-wrap: break-word !important;">' + verify.verifyReason + '</pre></p>'
	
		
	
	verifyDetailHtml += '<hr/><p style="text-align: center; color: #6294AD;"><b>报修信息</b></p>'
		+	'<p>id：' + verify.bill.id + '</p>'
		+	'<p>客户客户：' + verify.customerName + '</p>'
		+	'<p>报修设备：' + verify.deviceName + '</p>'
		+	'<p>报修时间：' + moment(verify.bill.createTime).format('YYYY-MM-DD HH:mm:ss') + '</p>'
		+	'<p>损坏描述：<pre style="white-space: pre-wrap !important;word-wrap: break-word !important;">' + verify.bill.billDesc + '</pre></p>'
		+	'<p>损坏图片：<div class="detailImageDiv"><img style="display:block; margin:0 auto;" src="' + verify.bill.billImageUrl + '"/><div></p>';

	$("#verifyDetailShow").html(verifyDetailHtml);
	$("#verifyDetailModal").modal("show");
}

 
